package burubaka.controller.mnt;

import org.slim3.controller.Navigation;
import org.slim3.util.BeanUtil;

import burubaka.common.controller.Controller;
import burubaka.model.SystemInfo;
import burubaka.service.SystemInfoService;

import com.google.appengine.api.datastore.Text;

public class SystemInfoController extends Controller {

	SystemInfoService systemInfoService = new SystemInfoService();

	@Override
	public Navigation init() throws Exception {

		SystemInfo si = systemInfoService.getSystemInfo();

		requestScope("systemInfo", si);
		return forward("systemInfo.jsp");
	}

	/**
	 * 登録
	 * 
	 * @return Navigation
	 * @throws Exception
	 */
	public Navigation regist() throws Exception {

		SystemInfo si = new SystemInfo();
		BeanUtil.copy(request, si);
		requestScope("systemInfo", si);
		si.setTopInfoArea1(new Text(asString("tpInfoArea1")));
		si.setMypageInfoArea1(new Text(asString("mpInfoArea1")));
		if (reqMap.get("pk") != null && !reqMap.get("pk").equals("")) {
			si.setKey(systemInfoService.getKey(asLong("pk")));
		}
		systemInfoService.regist(si);
		requestScope("systemInfo", si);
		return forward("systemInfo.jsp");
	}

	public Navigation preview() throws Exception {
		SystemInfo si = new SystemInfo();
		BeanUtil.copy(request, si);
		requestScope("systemInfo", si);
		si.setTopInfoArea1(new Text(asString("tpInfoArea1")));
		si.setMypageInfoArea1(new Text(asString("mpInfoArea1")));
		if (reqMap.get("pk") != null && !reqMap.get("pk").equals("")) {
			si.setKey(systemInfoService.getKey(asLong("pk")));
		}
		requestScope("systemInfo", si);
		return forward("systemInfo.jsp");
	}
}
